home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 8206 / 8206.xpi / content / rss / feed.wrapper.js next >
Text File  |  2010-02-02  |  2KB  |  92 lines

  1. WiseStampFeedWrapper.prototype = new Object;
  2. WiseStampFeedWrapper.prototype.format = WiseStampFeedWrapper_format;
  3. WiseStampFeedWrapper.prototype.formatNoHtml = WiseStampFeedWrapper_formatNoHtml;
  4. WiseStampFeedWrapper.prototype.getLatestPost = WiseStampFeedWrapper_getLatestPost;
  5. WiseStampFeedWrapper.prototype.refreshCache = WiseStampFeedWrapper_refreshCache;
  6. WiseStampFeedWrapper.prototype.setLatestPostInCache = WiseStampFeedWrapper_setLatestPostInCache;
  7.  
  8. function WiseStampFeedWrapper(feed, formatter)
  9. {
  10.     this._feed = feed;
  11.     this._formatter = formatter;
  12.     this._latestPostCached = null;
  13.     this._latestPostCachedDate = null;
  14.     this.CACHE_TIMEOUT = 5 * 60 * 1000; // sasha
  15. }
  16.  
  17. function WiseStampFeedWrapper_format()
  18. {
  19.     if (!this._latestPostCached)
  20.     {
  21.         return '';
  22.     };
  23.     return this._formatter.format(this._latestPostCached);
  24. }
  25.  
  26. function WiseStampFeedWrapper_formatNoHtml()
  27. {
  28.     if (!this._latestPostCached)
  29.     {
  30.         return '';
  31.     };
  32.  
  33.     return this._formatter.formatNoHtml(this._latestPostCached);
  34. }
  35.  
  36. function WiseStampFeedWrapper_getLatestPost()
  37. {
  38.     return this._latestPostCached;
  39. }
  40.  
  41. function WiseStampFeedWrapper_refreshCache(callback)
  42. {
  43.     WiseStampUtils.log("[feed.wrapper.js::WiseStampFeedWrapper_refreshCache] >>>>>");
  44.     var _this = this;
  45.  
  46.     var expired = false;
  47.  
  48.     if (this._latestPostCachedDate)
  49.     {
  50.         var current = new Date();
  51.         var expires = new Date().setTime(this._latestPostCachedDate.getTime() + this.CACHE_TIMEOUT);
  52.         //dump("CURRENT: "); dump(current.toString());
  53.         //dump("EXPIRES: "); dump(expires.toString());
  54.         //dump("\n");
  55.         expired = expires < current;
  56.         //WiseStampUtils.log("[feed.wrapper.js::WiseStampFeedWrapper_refreshCache] current="+current+", expires="+expires.toString()+", expired="+expired);
  57.     };
  58.  
  59.     if (this._latestPostCached && !expired)
  60.     {
  61.         WiseStampUtils.log("[feed.wrapper.js::WiseStampFeedWrapper_refreshCache] return cached");
  62.     
  63.         //dump("NOT EXPIRED\n");
  64.         callback();
  65.         return;
  66.     };
  67.  
  68.     WiseStampUtils.log("[feed.wrapper.js::WiseStampFeedWrapper_refreshCache] fetching new...");
  69.     
  70.     this._feed.fetch(function (content)
  71.     {
  72.         var filter = new WiseStampRSSDataFilter();
  73.         var latestPost = filter.getLatestPost(content);
  74.  
  75.         if (!latestPost)
  76.         {
  77.             callback();
  78.             return;
  79.         };
  80.  
  81.         _this.setLatestPostInCache(latestPost);
  82.         callback();
  83.         return;
  84.     });
  85.     //      window.setTimeout(function() { throw new Error("[debug] " + "6c - "); }, 0);
  86. }
  87.  
  88. function WiseStampFeedWrapper_setLatestPostInCache(post)
  89. {
  90.     this._latestPostCachedDate = new Date();
  91.     this._latestPostCached = post;
  92. }